package com.employee.controller;

import com.employee.pojo.dto.PositionDto;
import com.employee.pojo.dto.UpdatePosDto;
import com.employee.pojo.entry.PosHistory;
import com.employee.pojo.entry.Position;
import com.employee.pojo.result.Result;
import com.employee.pojo.vo.PosStaffVo;
import com.employee.service.PosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PosController {
    @Autowired
    private PosService posService;


    @GetMapping("/getPosHis/{id}")
    public Result<List<PosHistory>> getPosList(@PathVariable("id") Long id) {
        return Result.success(posService.getPosList(id));
    }
    @GetMapping("/getPos")
    public Result<List<Position>> getPosition() {
        List<Position> positionList = posService.getPositionList();
        return Result.success(positionList);
    }
    @GetMapping("/getPos/{id}")
    public Result<Position> getOnePosition(@PathVariable("id") Long id) {
        Position position = posService.getPosById(id);
        return Result.success(position);
    }
    @GetMapping("/getPosStaffList/{id}")
    public Result<List<PosStaffVo>> getStaffByPositionId(@PathVariable("id") Long id) {
        return Result.success(posService.getStaffList(id));
    }
    @PostMapping("/addPos")
    public Result addPosition(@RequestBody PositionDto positionDto) {

        posService.addPosition(positionDto);
        return Result.success();
    }
    @PostMapping("/updatePos")
    public Result updatePosition(@RequestBody UpdatePosDto positionDto) {
        posService.updatePosition(positionDto);
        return Result.success();
    }
    @GetMapping("/selectPos")
    public Result<List<Position>> selectPosition(@RequestParam("posName") String posName, @RequestParam("posStatus") String status) {
        List<Position> positionList = posService.getPosListByQuery(posName, status);
        return Result.success(positionList);
    }
    @GetMapping("/updateStatus/{posId}/{posStatus}")
    public Result updateStatus(@PathVariable("posId") Long posId, @PathVariable("posStatus") String status) {
        posService.updateStatus(posId,status);
        return Result.success();
    }
}
